/**
 * Project  : monkey
 * Author   : Wu Tian Qiang
 * Date     : 2016/10/18 20:49:30
 */
Ext.define('Monkey.view.user.StatusHistoryWindow', {
    extend: 'Ext.window.Window',

    userId: '',
    nick: '',
    closable: true,
    resizable: false,
    constrain: true,
    constrainHeader: true,
    modal: true,
    frameHeader: false,
    frame: true,
    maximizable: false,
    icon: 'resources/icons/16/report_user.png',
    layout: 'fit',
    width: 600,
    height: 300,
    initComponent: function () {
        if (Ext.isEmpty(this.userId)) {
            Ext.raise('userId属性不能为空');
        }
        if (Ext.isEmpty(this.nick)) {
            Ext.raise('nick属性不能为空');
        }
        this.title = '查看状态改变记录(昵称：' + this.nick + ')';

        var statusHistoryStore = Ext.create('Monkey.store.BaseStore', {
            autoLoad: true,
            fields: [
                {name: 'id', type: 'int'},
                {name: 'status', type: 'string'},
                {
                    name: 'opUser', type: 'string',
                    mapping: function (data) {
                        return data.opUser.nick;
                    }
                },
                {name: 'opDate', type: 'string'},
                {name: 'reason', type: 'string'}
            ],
            proxy: {
                type: 'ajax',
                pageParam: 'page.pn',
                limitParam: 'page.size',
                url: Monkey.URL.SERVER_URL + "/m/user/status_histories.json",
                extraParams: {
                    fields: 'id,status,opDate,reason,opUser[nick]',
                    'search.user.id_eq': this.userId
                },
                reader: {
                    type: 'json',
                    totalProperty: 'data.totalAmount',
                    rootProperty: 'data.elements'
                }
            }
        });


        this.items = [{
            xtype: 'grid',
            border: false,
            reference: 'statusHistoryGrid',
            store: statusHistoryStore,
            bbar: {
                xtype: 'pagingtoolbar',
                pageSize: 10,
                store: statusHistoryStore,
                displayInfo: true,
                plugins: new Ext.ux.ProgressBarPager()
            },
            columns: [{
                width: 30,
                xtype: 'rownumberer'
            }, {
                text: 'id',
                dataIndex: 'id',
                hidden: true,
                width: 100
            }, {
                text: '状态',
                dataIndex: 'status',
                width: 100,
                renderer: function (data) {
                    return data == 'NORMAL' ? '正常状态' : '禁用状态';
                }
            }, {
                text: '操作人员',
                dataIndex: 'opUser',
                width: 100
            }, {
                text: '操作时间',
                dataIndex: 'opDate',
                width: 150
            }, {
                text: '原因',
                dataIndex: 'reason',
                flex: 1
            }]
        }];
        this.callParent();
    }
});